import axios from 'axios'
export default {
  namespaced: true,
  state: () => ({
    // 存入token
    token: localStorage.getItem('token') || '',
    // 用户个人信息
    UserInfo: {}
  }),
  mutations: {
    // 把token存入vuex中
    DepositToken (state, token) {
      state.token = token
      localStorage.setItem('token', token)
    },
    updateUserInfo (state, userinfo) {
      state.UserInfo = userinfo
    }
  },
  actions: {
    // 异步操作获取用户信息
    async gitInfo (conext) {
      const { data: res } = await axios({
        method: 'GET',
        url: '/my/userinfo'
      })
      //  获取用户信息成功后要存入vuex里面方面以后调用
      conext.commit('updateUserInfo', res.data)
    }
  },
  getters: {}
}
